package com.p595263720.o_amap.map.models;

import android.graphics.Color;

import com.amap.api.maps.AMap;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.PolylineOptions;

import java.util.List;

public class UnifiedPolylineOptions {
    /// 顶点
    private List<LatLng> latLngList;
    /// 线段的宽度
    double width;
    /// 线段的颜色
    String color;
    /// 线段的Z轴值
    private double zIndex;
    /// 线段的可见属性
    private boolean isVisible;
    /// 线段是否画虚线，默认为false，画实线
    private boolean isDottedLine;
    /// 线段是否为大地曲线，默认false，不画大地曲线
    private boolean isGeodesic;
    /// 虚线形状
    private int dottedLineType;
    /// Polyline尾部形状
    private int lineCapType;
    /// Polyline连接处形状
    private int lineJoIntype;
    /// 线段是否使用渐变色
    private boolean isUseGradient;
    /// 线段是否使用纹理贴图
    private boolean isUseTexture;

    public void applyTo(AMap map) {
        map.addPolyline(toPolylineOptions());
    }

    private PolylineOptions toPolylineOptions() {
        PolylineOptions.LineCapType lineCapType1 = PolylineOptions.LineCapType.LineCapButt;
        if (lineCapType == 0) {
            lineCapType1 = PolylineOptions.LineCapType.LineCapButt;
        } else if (lineCapType == 1) {
            lineCapType1 = PolylineOptions.LineCapType.LineCapSquare;
        } else if (lineCapType == 2) {
            lineCapType1 = PolylineOptions.LineCapType.LineCapArrow;
        } else {
            lineCapType1 = PolylineOptions.LineCapType.LineCapRound;
        }
        PolylineOptions.LineJoinType lineJoinType1 = PolylineOptions.LineJoinType.LineJoinBevel;
        if (lineJoIntype == 0) {
            lineJoinType1 = PolylineOptions.LineJoinType.LineJoinBevel;
        } else if (lineJoIntype == 1) {
            lineJoinType1 = PolylineOptions.LineJoinType.LineJoinMiter;
        } else {
            lineJoinType1 = PolylineOptions.LineJoinType.LineJoinRound;

        }
        return new PolylineOptions()
                .addAll(latLngList)
                .width((float) width)
                .color(Color.parseColor("#" + color))
                .zIndex((float) zIndex)
                .visible(isVisible)
                .setDottedLine(isDottedLine)
                .geodesic(isGeodesic)
                .setDottedLineType(dottedLineType)
                .useGradient(isUseGradient)
                .setUseTexture(isUseTexture)
                .lineCapType(lineCapType1)
                .lineJoinType(lineJoinType1);

    }
}
